package com.wing.product.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 产品
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("pro_product")
public class Product extends BaseEntity<Product> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum PricingMethod implements IEnum<Integer> {

        /**
         * 按件
         */
        piece(0,"按件"),
        /**
         * 按重量
         */
        weight(1,"按重量");

        private int code;
        private String desc;

        PricingMethod(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static Product.PricingMethod jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (Product.PricingMethod item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    public enum Type implements IEnum<Integer> {

        /**
         * 刀具
         */
        knife(0,"刀具"),
        /**
         * 柜子
         */
        cabinet(1,"柜子");

        private int code;
        private String desc;

        Type(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum CabinetNature implements IEnum<Integer> {

        /**
         * 主柜
         */
        main(0,"主柜"),
        /**
         * 售刀副柜
         */
        sale(1,"售刀副柜"),
        /**
         * 存刀副柜
         */
        live(2,"存刀副柜");

        private int code;
        private String desc;

        CabinetNature(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static Product.CabinetNature jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (Product.CabinetNature item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }


    public enum CabNatureType implements IEnum<Integer> {

        /**
         * 实体
         */
        entity(0,"实体"),
        /**
         * 虚拟
         */
        virtual(1,"虚拟");

        private int code;
        private String desc;

        CabNatureType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static Product.CabNatureType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (Product.CabNatureType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    public enum DataSourceType implements IEnum<Integer> {

        /**
         * 自采
         */
        oneself(0,"自采"),
        /**
         * 平台
         */
        platform(1,"平台"),
        /**
         * 本地
         */
        local(2,"本地");

        private int code;
        private String desc;

        DataSourceType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 商品名称
     */
    private String name;

    /**
     * 入驻企业ID
     */
    private Long settledCompanyId;

    /**
     * 入驻企业名称
     */
    @TableField(exist = false)
    private String settledCompanyName;

    /**
     * 产品类型
     */
    private Long productTypeId;

    /**
     * 产品分类
     */
    private Long productCategoryId;

    /**
     * 产品分类名称
     */
    @TableField(exist = false)
    private String productCategoryName;

    /**
     * 关键词
     */
    private String keyword;

    /**
     * 卖点描述
     */
    private String sellingPointSpec;

    /**
     * 计价方式
     */
    private PricingMethod pricingMethod;

    /**
     * 计价方式描述
     */
    @TableField(exist = false)
    private String pricingMethodDesc;

    public String getPricingMethodDesc() {
        return pricingMethod == null ? null : pricingMethod.getDesc();
    }

    /**
     * 单位
     */
    private Long unitId;

    /**
     * 单位名称
     */
    @TableField(exist = false)
    private String unitName;

    /**
     * 商品图片
     */
    private String picture;

    /**
     * 商品描述
     */
    private String description;

    /**
     * 排序
     */
    private Integer sortNumber;

    /**
     * 产品编码
     */
    private String productCode;

    /**
     * 产品品牌编号
     */
    private String brandCode;

    /**
     * 产品品牌ID
     */
    private Long brandId;

    /**
     * 产品品牌名称
     */
    private String brandName;

    /**
     * 类型
     */
    private Type type;

    /**
     * 产品类型名称
     */
    @TableField(exist = false)
    private String productTypeName;

    /**
     * 类型描述
     */
    @TableField(exist = false)
    private String typeDesc;

    public String getTypeDesc() {
        return type == null ? null : type.getDesc();
    }

    /**
     * 企业产品ID
     */
    private Long companyProId;


    /**
     * 扩展产品分类ID
     */
    @TableField(exist = false)
    private String productCategoryExtId;

    /**
     * 产品扩展分类名称
     */
    @TableField(exist = false)
    private String productCategoryExtName;

    /**
     * 产品SKU明细
     */
    @TableField(exist = false)
    private List<ProductDetail> productDetailList;

    /**
     * 保存前端传过来的属性信息
     */
    @TableField(exist = false)
    private List<ProductDetailAttribute> productDetailAttribute;

    /**
     * 企业编号
     */
    @TableField(exist = false)
    private String enterpriseCode;

    /**
     * 状态:up(0,上架);down(1,下架)
     */
    public enum Status implements IEnum<Integer> {

        /**
         * 上架
         */
        up(0,"上架"),
        /**
         * 下架
         */
        down(1,"下架");

        private int code;
        private String desc;

        Status(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    /**
     * 状态
     */
    private Product.Status status;

    /**
     * 状态描述
     */
    @TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        return status == null ? null : status.getDesc();
    }

    /**
     * 刀柜性质
     */
    private CabinetNature cabinetNature;
    /**
     * 刀柜性质描述
     */
    @TableField(exist = false)
    private String cabinetNatureDesc;

    public String getCabinetNatureDesc() {
        return cabinetNature == null ? null : cabinetNature.getDesc();
    }

    /**
     * 刀柜性质状态
     */
    private CabNatureType cabNatureType;

    /**
     * 刀柜性质状态描述
     */
    @TableField(exist = false)
    private String cabNatureTypeDesc;

    public String getCabNatureTypeDesc() {
        return cabNatureType == null ? null : cabNatureType.getDesc();
    }

    /**
     * 数据来源
     */
    private DataSourceType dataSourceType;

    /**
     * 平台端表id
     */
    private Long idPlatform;

    /**
     * 是否已同步：no(0,未同步);yes(1,已同步);
     */
    private Integer isSyns;

    /**
     * 同步时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime synsTime;

    /**
     * 是否从本地导入
     */
    private Long isLocalImport;

    @TableField(exist = false)
    private String uniqCode;

    private String remark;

    /**
     * 规格码
     */
    private String specCode;
}
